#!/bin/bash
# 自动推送脚本

# 需要设置本地仓库的绝对位置
path_repo="/root/Contribution"

# 获取当前的日期和时间
_date=`date +%Y-%m-%d`
_time=`date +%H:%M:%S`

# 判断本地仓库是否存在
if [ -e ${path_repo} ]
then
	echo "${_date}-${_time}: ${path_repo} exists" >> ～/.log
else
	echo "${_date}-${_time}: ${path_repo} does not exists" >> ~/.log
fi

# 判断本地仓库的权限：是否可读
if [ -r ${path_repo} ]
then
	echo "${_date}-${_time}: ${path_repo} can be readable" >> ~/.log
else
	echo "${_date}-${_time}: ${path_repo} can not be readable" >> ~/.log
fi

# 创建推送内容所在的文件夹
folder="${path_repo}/${_date}/${_time}"
mkdir -p ${folder}

# 新建README.md作为推送的内容
cat > ${folder}/README.md << EOF
# Push automatically at ${_date} ${_time}
# This file will be deleted tomorrow.
EOF

# 进入仓库
cd ${path_repo}

# 进行提交
git add .
git commit -m "Add ${folder}/README.md"
git push -u origin master
git push -u github master
echo "${_date}-${_time}: auto push successfully" >> ~/.log


